'use strict';

const { parseParams, parseSimpleObject } = require('../lib/utils');

module.exports = function agent_plugin(md, page) {
    let agent_id = 0;
    const projectName = page.config.projectName;
    md.renderer.rules.fence_custom.agent = function(params, tokens, idx) {
        const options = parseParams(params, { name: 'Merlin' });
        const method = tokens[idx].content.split('\n').filter(o=>!!o).map(o=>`${o.trim()}`).join('');
        agent_id++;
        return `
        <svg id="mdoc_agent_${agent_id}" class="agent_svg"></svg>
        <script>
        $(document).ready(function(){
            clippy.BASE_PATH = '/${projectName}/agent/agents/';
            clippy.load('${options.name}', ${method});
        });
        </script>
        `;
    };
};
